package com.bw.service;

import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;
import java.util.UUID;

@Component
public class ProServiceImpl implements ProService{
    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    //4.编写定时任务，每分钟执行一次该任务（10分）
    @Scheduled(cron = "0 * * * * *")
    public boolean send(){
       //每次执行该任务 发送n条消息，n为30 到 120之间的随机数
        Random random = new Random();
        int n=random.nextInt(91)+30;
        System.out.println("定时任务"+n);
        //保证任何两次消息都不相同
        for (int i = 0; i < n; i++) {
            String substring = UUID.randomUUID().toString().substring(0, 8);
            rocketMQTemplate.convertAndSend("xixi1",substring);
        }
        return true;
    }
}
